﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Cn.Edwon.Web;
using Cn.Cellula.Biz;

namespace Cn.Cellula.Client {
    public class SiteConfig {

        #region 全局常量
        public const Int32 SMTP_PORT_DEFAULT = 25;
        #endregion

        /// <summary>
        /// 注册校验方式
        /// </summary>
        public enum RegisterCheck { 
            None = 10,
            Man = 20,
            Email = 30
        }
        #region Web.Config文件的方式

        #region 系统
        public class System {
            public static String DbType {
                get {
                    String val = WebConfig.GetAppSetting(AppSettingsKey.SysDbType,"");
                    switch (val) {
                        case CodeTypeDef.DbType.MySql5:
                            return CodeTypeDef.DbType.MySql5;
                        case CodeTypeDef.DbType.Oracle10g:
                            return CodeTypeDef.DbType.Oracle10g;
                        default:
                            return "";
                    }
                }
            }
        }
        #endregion

        #region 基本信息
        public class BaseInfo {
            public static String SiteName {
                get {
                    return WebConfig.GetAppSetting(AppSettingsKey.SysSiteName,"");
                }
            }
            public static String LogoUrl {
                get {
                    String _url = WebConfig.GetAppSetting(AppSettingsKey.SysLogoUrl,"");
                    if (_url!=null && _url.IndexOf(":") != -1 || _url.IndexOf("/") == 0) {
                        return _url;
                    } else {
                        return ClientHelper.RootUrl + _url;
                    }
                }
            }
            public static String PageTitle {
                get {
                    return WebConfig.GetAppSetting(AppSettingsKey.SysPageTitle,"");
                }
            }
            public static String Copyright {
                get {
                    return WebConfig.GetAppSetting(AppSettingsKey.SysCopyright,"");
                }
            }
        }
        #endregion

        #region 用户系统
        public class Sercurity {
            public static String UserLoginProperty {
                get {
                    return WebConfig.GetAppSetting(AppSettingsKey.UserLoginProperty,"");
                }
            }
            public static RegisterCheck UserRegCheck {
                get {
                    try {
                        return (RegisterCheck)Enum.Parse(typeof(RegisterCheck), WebConfig.GetAppSetting(AppSettingsKey.UserRegCheck,""));
                    } catch {
                        return RegisterCheck.None;
                    }
                }
            }
        }
        #endregion

        #region 上传相关
        public class Upload {
            /// <summary>
            /// 上传文件相对于根的目录名
            /// </summary>
            public static String UploadForder {
                get {
                    String path = WebConfig.GetAppSetting(AppSettingsKey.SysUploadPath,"");
                    path = path.Replace("\\", "/");
                    if (path.IndexOf("/") == -1 || path.Substring(path.LastIndexOf("/")) != "/") {
                        path += "/";
                    }
                    return path;
                }
            }
            /// <summary>
            /// 上传文件总目录的Path路径
            /// </summary>
            public static String UploadPath {
                get {
                    String path = UploadForder;
                    if (path.IndexOf(":") != -1) {
                        return path;
                    } else {
                        return ClientHelper.RootPath + path;
                    }
                }
            }
            /// <summary>
            /// 上传文件总目录的URL路径
            /// </summary>
            public static String UploadUrl {
                get {
                    String path = UploadForder;
                    if (path.IndexOf(":") != 1) {
                        return path;
                    } else {
                        return ClientHelper.RootUrl + path;
                    }
                }
            }
            /// <summary>
            /// 缩略图最大宽度
            /// </summary>
            public static int ThumbnailMaxWidth {
                get {
                    try {
                        int val = Convert.ToInt32(WebConfig.GetAppSetting(AppSettingsKey.ThumbnailMaxWidth,""));
                        if (val <= 0) val = 100;
                        return val;
                    } catch {
                        return 100;
                    }
                }
            }
            /// <summary>
            /// 缩略图最大高度
            /// </summary>
            public static int ThumbnailMaxHeight {
                get {
                    try {
                        int val = Convert.ToInt32(WebConfig.GetAppSetting(AppSettingsKey.ThumbnailMaxHeight,""));
                        if (val <= 0) val = 100;
                        return val;
                    } catch {
                        return 100;
                    }
                }
            }
            public static String UploadFilePattern {
                get {
                    return WebConfig.GetAppSetting(AppSettingsKey.SysUploadFilePattern,"");
                }
            }
            public static String UploadImagePattern {
                get {
                    return WebConfig.GetAppSetting(AppSettingsKey.SysUploadImagePattern,"");
                }
            }
        }
        #endregion

        #region 产品相关
        public class Product {
            /// <summary>
            /// 商品编号是否自动生成，1：自动，0：手动录入
            /// </summary>
            public static Boolean ProductNoAuto {
                get {
                    return (WebConfig.GetAppSetting2Boolean(AppSettingsKey.ProductNoAuto,true));
                }
            }
        }
        #endregion

        #region 邮件服务
        public class Smtp {
            public static String SmtpServer {
                get {
                    return WebConfig.GetAppSetting(AppSettingsKey.SmtpServer,"");
                }
            }
            public static String SmtpUser {
                get {
                    return WebConfig.GetAppSetting(AppSettingsKey.SmtpUser, "");
                }
            }
            public static String SmtpPwd {
                get {
                    return WebConfig.GetAppSetting(AppSettingsKey.SmtpPwd, "");
                }
            }
            public static String SmtpFrom {
                get {
                    return WebConfig.GetAppSetting(AppSettingsKey.SmtpFrom, "");
                }
            }
            public static Int32 SmtpPort {
                get {
                    try {
                        return Convert.ToInt32(WebConfig.GetAppSetting(AppSettingsKey.SmtpPort, ""));
                    } catch {
                        return SMTP_PORT_DEFAULT;
                    }

                }
            }
            public static Boolean SmtpSSL {
                get {
                    try {
                        String val = WebConfig.GetAppSetting(AppSettingsKey.SmtpSSL, "");
                        val = (val != null) ? val.ToLower() : "";
                        return (val == "1" || val == "yes" || val=="true");
                    } catch {
                        return false;
                    }

                }
            }
        }
        #endregion

        #region 系统参数
        #region 日程相关
        public class Calendar {
            public static String TodoRef { 
                get{
                    return WebConfig.GetAppSetting(AppSettingsKey.TodoRefItemCategoryKey,"");
                }
            }
        } 
        #endregion

        #endregion

        #endregion

        #region 数据库方式
        /*
        private static String _UploadFilePattern;
        /// <summary>
        /// 
        /// </summary>
        public static String UploadFilePattern {
            get { return _UploadFilePattern; }
            set { _UploadFilePattern = value; }
        }


        private static String _UploadImagePattern;
        /// <summary>
        /// 
        /// </summary>
        public static String UploadImagePattern {
            get { return _UploadImagePattern; }
            set { _UploadImagePattern = value; }
        }


        private static String _SiteName;
        /// <summary>
        /// 
        /// </summary>
        public static String SiteName {
            get { return _SiteName; }
            set { _SiteName = value; }
        }


        private static String _LogoUrl;
        /// <summary>
        /// 
        /// </summary>
        public static String LogoUrl {
            get { return _LogoUrl; }
            set { _LogoUrl = value; }
        }


        private static String _PageTitle;
        /// <summary>
        /// 
        /// </summary>
        public static String PageTitle {
            get { return _PageTitle; }
            set { _PageTitle = value; }
        }


        private static String _Copyright;
        /// <summary>
        /// 
        /// </summary>
        public static String Copyright {
            get { return _Copyright; }
            set { _Copyright = value; }
        }


        private static String _UserLoginProperty;
        /// <summary>
        /// 
        /// </summary>
        public static String UserLoginProperty {
            get { return _UserLoginProperty; }
            set { _UserLoginProperty = value; }
        }


        private static String _UploadForder;
        /// <summary>
        /// 
        /// </summary>
        public static String UploadForder {
            get { return _UploadForder; }
            set { _UploadForder = value; }
        }


        private static String _UploadPath;
        /// <summary>
        /// 
        /// </summary>
        public static String UploadPath {
            get { return _UploadPath; }
            set { _UploadPath = value; }
        }


        private static String _UploadUrl;
        /// <summary>
        /// 
        /// </summary>
        public static String UploadUrl {
            get { return _UploadUrl; }
            set { _UploadUrl = value; }
        }


        private static Int32 _ThumbnailMaxWidth;
        /// <summary>
        /// 
        /// </summary>
        public static Int32 ThumbnailMaxWidth {
            get { return _ThumbnailMaxWidth; }
            set { _ThumbnailMaxWidth = value; }
        }


        private static Int32 _ThumbnailMaxHeight;
        /// <summary>
        /// 
        /// </summary>
        public static Int32 ThumbnailMaxHeight {
            get { return _ThumbnailMaxHeight; }
            set { _ThumbnailMaxHeight = value; }
        }


        private static Boolean _ProductNoAuto;
        /// <summary>
        /// 
        /// </summary>
        public static Boolean ProductNoAuto {
            get { return _ProductNoAuto; }
            set { _ProductNoAuto = value; }
        }


        private static RegisterCheck _UserRegCheck;
        /// <summary>
        /// 
        /// </summary>
        public static RegisterCheck UserRegCheck {
            get { return _UserRegCheck; }
            set { _UserRegCheck = value; }
        }


        private static String _UserRoleDefault;
        /// <summary>
        /// 
        /// </summary>
        public static String UserRoleDefault {
            get { return _UserRoleDefault; }
            set { _UserRoleDefault = value; }
        }
        */
        #endregion

    }
}